<!DOCTYPE html>
<html>
<head>
<title>test.html</title>
<meta charset="utf-8">
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

</head>

<body>
	<a id="A">aaa</a>
</body>
<script type="text/javascript"
	src="./lib/jquery/1.9.1/jquery.min.js"></script>
<script src="./lib/aes.js"></script>
<script type="text/javascript">
	$(function() {
		$("#A")
				.on(
						"click",
						function() {
							var key = CryptoJS.enc.Utf8
									.parse("8NONwyJtHesysWpM");
							var plaintText = 'ABCDEFGH'; // 明文  
							var encryptedData = CryptoJS.AES.encrypt(
									plaintText, key, {
										mode : CryptoJS.mode.ECB,
										padding : CryptoJS.pad.Pkcs7
									});

							console.log("加密前：" + plaintText);
							console.log("加密后：" + encryptedData);
							encryptedData = encryptedData.ciphertext.toString();
							console.log("加密后2：" + encryptedData);
							
							var encryptedHexStr = CryptoJS.enc.Hex
									.parse(encryptedData);
							var encryptedBase64Str = CryptoJS.enc.Base64
									.stringify(encryptedHexStr);
							var decryptedData = CryptoJS.AES.decrypt(
									encryptedBase64Str, key, {
										mode : CryptoJS.mode.ECB,
										padding : CryptoJS.pad.Pkcs7
									});

							var decryptedStr = decryptedData
									.toString(CryptoJS.enc.Utf8);
							console.log("解密后:" + decryptedStr);
							var pwd = "PCsUFtgog9/qpqmqXsuCRQ==";
							//加密服务端返回的数据  
							var decryptedData = CryptoJS.AES.decrypt(pwd, key,
									{
										mode : CryptoJS.mode.ECB,
										padding : CryptoJS.pad.Pkcs7
									});

							console.log("解密服务端返回的数据:" + decryptedStr);
						});
	});
</script>
</html>
